package cg.studio.algorithm.collection;

import org.junit.Test;


public class CollectionsTester
{
  @Test
  public void testMergeSortedList()
  {
    testMergetSortedList( new Integer[]{ 3,4,5,6,7,8,20 }, new Integer[]{ 1,2,3,8,10,18 } );
    testMergetSortedList( new Integer[]{ 1 }, new Integer[]{ 2 } );
    testMergetSortedList( new Integer[]{1, 3, 5, 7, 9 }, new Integer[]{2, 4, 6, 8, 10 } );
    testMergetSortedList( null, new Integer[]{2, 4, 6, 8, 10 } );
    testMergetSortedList( new Integer[]{2, 4, 6, 8, 10 }, new Integer[]{2, 4, 6, 8, 10 } );
                         
  }
  
  public void testMergetSortedList( Integer[] arr1, Integer[] arr2 )
  {
    {
      Node<Integer> l1 = arr1 == null ? null : new Node<Integer>( arr1 );
      Node<Integer> l2 = arr2 == null ? null: new Node<Integer>( arr2 );
      Node<Integer> merged = Collections.mergeSortedList( l1, l2 );
      System.out.println( merged );
    }
    {
      Node<Integer> l1 = arr1 == null ? null : new Node<Integer>( arr1 );
      Node<Integer> l2 = arr2 == null ? null: new Node<Integer>( arr2 );
      Node<Integer> merged1 = Collections.mergeSortedList_1( l1, l2 );
      System.out.println( merged1 );
      System.out.println();
    }
    
  }
  
  
  //@Test
  public void testfindSingleNumber()
  {
    {
      int[] elements = new int[]{ 3 };
      System.out.println( "The number is: " + Collections.findSingleNumber( elements ) );
    }
    
    {
      int[] elements = new int[]{ 1,1,2,2,3 };
      System.out.println( "The number is: " + Collections.findSingleNumber( elements ) );
    }
    
    {
      int[] elements = new int[]{ 1,1,2,2,3,4,4 };
      System.out.println( "The number is: " + Collections.findSingleNumber( elements ) );
    }

    {
      int[] elements = new int[]{ 1,1,3,2,2,4,4 };
      System.out.println( "The number is: " + Collections.findSingleNumber( elements ) );
    }

  }
  
  
  //@Test
  public void testHasSum()
  {
    int[] arr = new int[]{ 2, 3, 4, 5, 8, 11, 18 };
    
    System.out.println( "has sum 5: " + Collections.hasSum( arr, 5 ) );
    
    System.out.println( "has sum 9: " + Collections.hasSum( arr, 9 ) );
    System.out.println( "has sum 16: " + Collections.hasSum( arr, 16 ) );
    
    System.out.println( "has sum 10: " + Collections.hasSum( arr, 10 ) );
    System.out.println( "has sum 17: " + Collections.hasSum( arr, 17 ) );
  }
}
